package com.whc.gulimall.order.web;

import com.whc.common.utils.RRException;
import com.whc.gulimall.order.designPattern.strategy.AliPay;
import com.whc.gulimall.order.designPattern.strategy.Pay;
import com.whc.gulimall.order.service.OrderService;
import com.whc.gulimall.order.vo.PayVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author angaoen
 */
@Controller
public class WebPayController {

    @Resource
    private OrderService orderService;

    @GetMapping(value = "/alipay", produces = {"text/html"})
    @ResponseBody
    public String alipay(@RequestParam("orderSn") String orderSn) {
        Pay pay = new Pay(new AliPay());
        PayVo payVo = orderService.createPayVO(orderSn);
        String payResult;
        try {
            payResult = pay.pay(payVo);
        } catch (Exception e) {
            throw new RRException("支付失败");
        }
        return payResult;
    }


}
